csv = require 'csv'
fs = require 'fs'
KEYWORLD_DISC_PATH = 'data/keyword_disc.csv'
KEYWORLD_PATH = 'data/keyword.csv'
delFile if (fs.unlinkSync KEYWORLD_DISC_PATH if fs.existsSync KEYWORLD_DISC_PATH)

discFun = (csvPath)->
    disMap = {}
    disArr = []
    console.log csvPath
    cc = 0
    csv()
    .from.path(csvPath)
    .on('record', (row,index)->
        console.log cc++,row[5]
        if !disMap[row[5]]
            console.log row.join ','
            disArr.push (row.join ',')
            disMap[row[5]]?=true
    )
    .on( 'end',(count)->
        console.log count
        fs.appendFileSync KEYWORLD_DISC_PATH , (disArr.join '\n') 
    )
    .on( 'error' ,(error)->
        console.log error
    )

run = (arg)->
    # console.log arg
    switch arg
        when 'disc'
            discFun KEYWORLD_PATH
        else
            for i in [0..2]
                console.log i

run 'disc'
